import dt from '@dt/dt'
import table from '@/components/dt/table/render.js'
import nameOpt from '@/biz/option/name.js'

function targetReachColumns(_this) {
  let vm = _this
  let head = [{
    title: '达成周期',
    field: 'week',
    minWidth: 250,
    fixed: 'left',
    tree: true,
  },
  {
    title: '本周目标',
    align: 'center',
    children: [{
      title: '目标线索',
      minWidth: 150,
      slots: {
        default: (params, h) => {
          return [h('div', vm.$tool.formatNumtoLocaleString(params.row.targetClue))]
        }
      }
    },
    {
      title: '目标来人',
      minWidth: 150,
      slots: {
        default: (params, h) => {
          return [h('div', vm.$tool.formatNumtoLocaleString(params.row.targetVisit))]
        }
      }
    },
    {
      title: '目标认购套数',
      minWidth: 150,
      slots: {
        default: (params, h) => {
          return [h('div', vm.$tool.formatNumtoLocaleString(params.row
            .targetSubscribe))]
        }
      }
    },
    {
      title: '目标签约套数',
      minWidth: 150,
      slots: {
        default: (params, h) => {
          return [h('div', vm.$tool.formatNumtoLocaleString(params.row.targetSign))]
        }
      }
    },
    {
      title: '目标签约金额（元）',
      minWidth: 150,
      slots: {
        default: (params, h) => {
          return [h('div', vm.$tool.formatterMoney(params.row.targetSignAmount))]
        }
      }
    },
    {
      title: '营销成本（元）',
      minWidth: 150,
      slots: {
        default: (params, h) => {
          return [h('div', vm.$tool.formatterMoney(params.row
            .targetMarketCostAmount))]
        }
      }
    }, ]
  },
  {
    title: '本周达成',
    align: 'center',
    children: [{
      title: '实际线索',
      minWidth: 150,
      slots: {
        default: (params, h) => {
          return [h('div', vm.$tool.formatNumtoLocaleString(params.row.realClue))]
        }
      }
    },
    {
      title: '实际来人',
      minWidth: 150,
      slots: {
        default: (params, h) => {
          return [h('div', vm.$tool.formatNumtoLocaleString(params.row.realVisit))]
        }
      }
    },
    {
      title: '实际认购套数',
      minWidth: 150,
      slots: {
        default: (params, h) => {
          return [h('div', vm.$tool.formatNumtoLocaleString(params.row
            .realSubscribe))]
        }
      }
    },
    {
      title: '实际签约套数',
      minWidth: 150,
      slots: {
        default: (params, h) => {
          return [h('div', vm.$tool.formatNumtoLocaleString(params.row.realSign))]
        }
      }
    },
    {
      title: '实际签约金额（元）',
      minWidth: 150,
      slots: {
        default: (params, h) => {
          return [h('div', vm.$tool.formatterMoney(params.row.realSignAmount))]
        }
      }
    },
    {
      title: '实际营销成本（元）',
      minWidth: 150,
      slots: {
        default: (params, h) => {
          return [h('div', vm.$tool.formatterMoney(params.row.realMarketCostAmount))]
        }
      }
    },
    {
      title: '本周回款（元）',
      minWidth: 150,
      slots: {
        default: (params, h) => {
          return [h('div', vm.$tool.formatterMoney(params.row.weekReturnAmount))]
        }
      }
    },
    {
      title: '联代签约套数',
      minWidth: 150,
      slots: {
        default: (params, h) => {
          return [h('div', vm.$tool.formatNumtoLocaleString(params.row
            .joinSignNumber))]
        }
      }
    }, ]
  },
  {
    field: 'createUser',
    minWidth: 100,
    title: '创建人'
  },
  {
    field: 'createDate',
    title: '创建日期',
    minWidth: 170,
    slots: {
      default: (params, h) => {
        return [h('div', vm.$tool.formatterDate(params.row.createDate))]
      }
    }
  },
  {
    field: 'handles',
    title: '操作',
    width: 130,
    align: 'center',
    fixed: 'right',
    slots: {
      default: (params, h) => {
        let btns = []
        let item = params.row
        item.type = 'edit'
        if (vm.unlocking('0107070202')) {
          btns.push({
            title: '修改',
            event: 'addFun',
            data: item
          })
        }

        return table.cell.btns(_this, h, btns)
      }
    }
  }, ]
  return head
}
//营销线路
function marketColumns() {
  const head = [{
      prop: 'customSource',
      label: '客户来源',
      type: '',
      editFlag: false
    },
    {
      prop: 'sourceType',
      label: '来源方式',
      type: '',
      editFlag: false
    },
    {
      prop: 'realClue',
      label: '实际线索',
      type: 'number',
      editFlag: true
    },
    {
      prop: 'realVisit',
      label: '实际来人',
      type: 'number',
      width: 120,
      editFlag: true
    },
    {
      prop: 'realSubscribe',
      label: '实际认购套数',
      type: 'number',
      editFlag: true,
    },
    {
      prop: 'realSign',
      label: '实际签约套数',
      type: 'number',
      editFlag: true,
    },
    {
      prop: 'realSignArea',
      label: '实际签约面积（m²）',
      type: 'decimal',
      editFlag: true,
    },
    {
      prop: 'realSignAmount',
      label: '实际签约金额（元）',
      type: 'decimal',
      editFlag: true
    },
    {
      prop: 'realMarketCostAmount',
      label: '实际营销成本（元）',
      type: 'decimal',
      editFlag: true
    },

  ]
  return head
}
//产品线路
const productColumn = [{
  prop: 'productSource',
  label: '产品类型',
  type: 'select',
  editFlag: true,
},
{
  prop: 'realClue',
  label: '实际线索',
  type: 'number',
  editFlag: true
},
{
  prop: 'realVisit',
  label: '实际来人',
  type: 'number',
  editFlag: true
},
{
  prop: 'realSubscribe',
  label: '实际认购套数',
  type: 'number',
  editFlag: true
},
{
  prop: 'realSign',
  label: '实际签约套数',
  type: 'number',
  editFlag: true
},
{
  prop: 'realSignReal',
  label: '实际签约面积（m²）',
  type: 'decimal',
  editFlag: true
},
{
  prop: 'realSignAmount',
  label: '实际签约金额（元）',
  type: 'decimal',
  editFlag: true
},
{
  prop: 'weekReturnAmount',
  label: '本周回款',
  type: 'decimal',
  editFlag: true
},
{
  prop: 'joinSignNumber',
  label: '联代签约套数',
  type: 'number',
  editFlag: true
},
{
  prop: 'operate',
  label: '操作',
  width: '110',
  type: 'operate',
  editFlag: false
}, ]

function productColumns(flag) {
  let productHead = []
  if (!flag) {
    productHead = productColumn.slice(0, productColumn.length - 1)
  } else {
    productHead = [...productColumn]
  }
  return productHead
}
export default {
  targetReachColumns,
  productColumns,
  marketColumns
}